<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
        }

        form {
            max-width: 400px;
            margin: 0 auto;
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        input {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 3px;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        a {
            color: #007BFF;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <form id="register">
        <h2>用户注册</h2>
        <label for="uId">登录ID</label>
        <input type="text" id="uId" name="uId">

        <label for="uName">真实姓名</label>
        <input type="text" id="uName" name="uName">

        <label for="uSex">性别</label>
        <input type="text" id="uSex" name="uSex" placeholder="请输入男/女">

        <label for="uEmail">E - Mail</label>
        <input type="email" id="uEmail" name="uEmail">

        <label for="uPassword">登录密码</label>
        <input type="password" id="uPassword" name="uPassword">



        <button type="button" onclick="rgis()">注册</button>
        <p class="text-center">已有账号，<a href="login.html">立即登录</a></p>
    </form>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script>

        function rgis() {
            event.preventDefault();
            $.ajax({
                type: "post",
                url: "/user/register",
                data: $("#register").serialize(),
                success: function (result) {
                    if (result == true) {
                        //成功
                        alert("注册成功");
                        location.href = "login.html";
                    } else {
                        alert("注册失败");
                    }

                },
                error: function (error) {
                    console.log('AJAX请求错误', error);
                    if (error.status == 401) {
                        location.href = "login.html";
                    }
                }
            });
        }
    </script>
</body>

</html>